package com.huawei.spare.part.replace.ssh;

import com.huawei.spare.part.replace.utils.SSHHelper;
import com.huawei.spare.part.replace.utils.SimplePTY;
import java.io.IOException;
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;
import net.sf.expectit.Result;

import static net.sf.expectit.matcher.Matchers.contains;

public class Telnet {

  public static void main(String[] args) throws IOException {
    final SSHClient ssh = new SSHClient();
    ssh.loadKnownHosts();
    ssh.addHostKeyVerifier(new PromiscuousVerifier());
    ssh.setConnectTimeout(20000);
    ssh.setTimeout(30000);
    ssh.connect("193.112.135.112");
    ssh.authPublickey("root");
    //ssh.getConnection().getKeepAlive().setKeepAliveInterval(5);
    //ssh.authPassword(username, password);
    try (SimplePTY pty = SimplePTY.allocate(ssh)) {
      pty.sendLine("telnet mx1.qq.com 25");
      pty.expect(contains("220"));
      pty.sendLine("Helo xmufive");
      pty.expect(contains("250"));

    }
  }

}
